<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>49.2. Zend_XmlRpc_Client</title>
<link rel="stylesheet" href="dbstyle.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.72.0">
<link rel="start" href="index.html" title="Programmer's Reference Guide">
<link rel="up" href="zend.xmlrpc.html" title="Chapter 49. Zend_XmlRpc">
<link rel="prev" href="zend.xmlrpc.html" title="Chapter 49. Zend_XmlRpc">
<link rel="next" href="zend.xmlrpc.server.html" title="49.3. Zend_XmlRpc_Server">
<link rel="chapter" href="introduction.html" title="Chapter 1. Introduction to Zend Framework">
<link rel="chapter" href="zend.acl.html" title="Chapter 2. Zend_Acl">
<link rel="chapter" href="zend.auth.html" title="Chapter 3. Zend_Auth">
<link rel="chapter" href="zend.cache.html" title="Chapter 4. Zend_Cache">
<link rel="chapter" href="zend.config.html" title="Chapter 5. Zend_Config">
<link rel="chapter" href="zend.console.getopt.html" title="Chapter 6. Zend_Console_Getopt">
<link rel="chapter" href="zend.controller.html" title="Chapter 7. Zend_Controller">
<link rel="chapter" href="zend.currency.html" title="Chapter 8. Zend_Currency">
<link rel="chapter" href="zend.date.html" title="Chapter 9. Zend_Date">
<link rel="chapter" href="zend.db.html" title="Chapter 10. Zend_Db">
<link rel="chapter" href="zend.debug.html" title="Chapter 11. Zend_Debug">
<link rel="chapter" href="zend.dojo.html" title="Chapter 12. Zend_Dojo">
<link rel="chapter" href="zend.dom.html" title="Chapter 13. Zend_Dom">
<link rel="chapter" href="zend.exception.html" title="Chapter 14. Zend_Exception">
<link rel="chapter" href="zend.feed.html" title="Chapter 15. Zend_Feed">
<link rel="chapter" href="zend.filter.html" title="Chapter 16. Zend_Filter">
<link rel="chapter" href="zend.form.html" title="Chapter 17. Zend_Form">
<link rel="chapter" href="zend.gdata.html" title="Chapter 18. Zend_Gdata">
<link rel="chapter" href="zend.http.html" title="Chapter 19. Zend_Http">
<link rel="chapter" href="zend.infocard.html" title="Chapter 20. Zend_InfoCard">
<link rel="chapter" href="zend.json.html" title="Chapter 21. Zend_Json">
<link rel="chapter" href="zend.layout.html" title="Chapter 22. Zend_Layout">
<link rel="chapter" href="zend.ldap.html" title="Chapter 23. Zend_Ldap">
<link rel="chapter" href="zend.loader.html" title="Chapter 24. Zend_Loader">
<link rel="chapter" href="zend.locale.html" title="Chapter 25. Zend_Locale">
<link rel="chapter" href="zend.log.html" title="Chapter 26. Zend_Log">
<link rel="chapter" href="zend.mail.html" title="Chapter 27. Zend_Mail">
<link rel="chapter" href="zend.measure.html" title="Chapter 28. Zend_Measure">
<link rel="chapter" href="zend.memory.html" title="Chapter 29. Zend_Memory">
<link rel="chapter" href="zend.mime.html" title="Chapter 30. Zend_Mime">
<link rel="chapter" href="zend.openid.html" title="Chapter 31. Zend_OpenId">
<link rel="chapter" href="zend.paginator.html" title="Chapter 32. Zend_Paginator">
<link rel="chapter" href="zend.pdf.html" title="Chapter 33. Zend_Pdf">
<link rel="chapter" href="zend.registry.html" title="Chapter 34. Zend_Registry">
<link rel="chapter" href="zend.rest.html" title="Chapter 35. Zend_Rest">
<link rel="chapter" href="zend.search.lucene.html" title="Chapter 36. Zend_Search_Lucene">
<link rel="chapter" href="zend.server.html" title="Chapter 37. Zend_Server">
<link rel="chapter" href="zend.service.html" title="Chapter 38. Zend_Service">
<link rel="chapter" href="zend.session.html" title="Chapter 39. Zend_Session">
<link rel="chapter" href="zend.soap.html" title="Chapter 40. Zend_Soap">
<link rel="chapter" href="zend.test.html" title="Chapter 41. Zend_Test">
<link rel="chapter" href="zend.text.html" title="Chapter 42. Zend_Text">
<link rel="chapter" href="zend.timesync.html" title="Chapter 43. Zend_TimeSync">
<link rel="chapter" href="zend.translate.html" title="Chapter 44. Zend_Translate">
<link rel="chapter" href="zend.uri.html" title="Chapter 45. Zend_Uri">
<link rel="chapter" href="zend.validate.html" title="Chapter 46. Zend_Validate">
<link rel="chapter" href="zend.version.html" title="Chapter 47. Zend_Version">
<link rel="chapter" href="zend.view.html" title="Chapter 48. Zend_View">
<link rel="chapter" href="zend.xmlrpc.html" title="Chapter 49. Zend_XmlRpc">
<link rel="appendix" href="requirements.html" title="Appendix A. Zend Framework Requirements">
<link rel="appendix" href="coding-standard.html" title="Appendix B. Zend Framework Coding Standard for PHP">
<link rel="appendix" href="copyrights.html" title="Appendix C. Copyright Information">
<link rel="index" href="the.index.html" title="Index">
<link rel="subsection" href="zend.xmlrpc.client.html#zend.xmlrpc.client.introduction" title="49.2.1. Introduction">
<link rel="subsection" href="zend.xmlrpc.client.html#zend.xmlrpc.client.method-calls" title="49.2.2. Method Calls">
<link rel="subsection" href="zend.xmlrpc.client.html#zend.xmlrpc.value.parameters" title="49.2.3. Types and Conversions">
<link rel="subsection" href="zend.xmlrpc.client.html#zend.xmlrpc.client.requests-and-responses" title="49.2.4. Server Proxy Object">
<link rel="subsection" href="zend.xmlrpc.client.html#zend.xmlrpc.client.error-handling" title="49.2.5. Error Handling">
<link rel="subsection" href="zend.xmlrpc.client.html#zend.xmlrpc.client.introspection" title="49.2.6. Server Introspection">
<link rel="subsection" href="zend.xmlrpc.client.html#zend.xmlrpc.client.request-to-response" title="49.2.7. From Request to Response">
<link rel="subsection" href="zend.xmlrpc.client.html#zend.xmlrpc.client.http-client" title="49.2.8. HTTP Client and Testing">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader"><table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">49.2. Zend_XmlRpc_Client</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="zend.xmlrpc.html">Prev</a> </td>
<th width="60%" align="center">Chapter 49. Zend_XmlRpc</th>
<td width="20%" align="right"> <a accesskey="n" href="zend.xmlrpc.server.html">Next</a>
</td>
</tr>
</table></div>
<div class="sect1" lang="en">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="zend.xmlrpc.client"></a>49.2. Zend_XmlRpc_Client</h2></div></div></div>
<div class="sect2" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="zend.xmlrpc.client.introduction"></a>49.2.1. Introduction</h3></div></div></div>
<p>
            The Zend Framework provides support for consuming remote XML-RPC
            services as a client in the <code class="code">Zend_XmlRpc_Client</code>
            package. Its major features include automatic type conversion
            between PHP and XML-RPC, a server proxy object, and access to
            server introspection capabilities.
        </p>
</div>
<div class="sect2" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="zend.xmlrpc.client.method-calls"></a>49.2.2. Method Calls</h3></div></div></div>
<p>
            The constructor of <code class="code">Zend_XmlRpc_Client</code> receives the
            URL of the remote XML-RPC server endpoint as its first parameter.
            The new instance returned may be used to call any number of
            remote methods at that endpoint.
        </p>
<p>
            To call a remote method with the XML-RPC client, instantiate it
            and use the <code class="code">call()</code> instance method. The code sample
            below uses a demonstration XML-RPC server on the Zend Framework
            website. You can use it for testing or exploring the
            <code class="code">Zend_XmlRpc</code> components.
        </p>
<div class="example">
<a name="zend.xmlrpc.client.method-calls.example-1"></a><p class="title"><b>Example 49.1. XML-RPC Method Call</b></p>
<div class="example-contents"><pre class="programlisting">&lt;?php
require_once 'Zend/XmlRpc/Client.php';

$client = new Zend_XmlRpc_Client('http://framework.zend.com/xmlrpc');

echo $client-&gt;call('test.sayHello');

// hello
            </pre></div>
</div>
<br class="example-break"><p>
            The XML-RPC value returned from the remote method call will be
            automatically unmarshaled and cast to the equivalent PHP native
            type. In the example above, a PHP <code class="code">string</code> is returned
            and is immediately ready to be used.
        </p>
<p>
            The first parameter of the <code class="code">call()</code> method receives the
            name of the remote method to call. If the remote method requires
            any parameters, these can be sent by supplying a second, optional
            parameter to <code class="code">call()</code> with an <code class="code">array</code> of
            values to pass to the remote method:
        </p>
<div class="example">
<a name="zend.xmlrpc.client.method-calls.example-2"></a><p class="title"><b>Example 49.2. XML-RPC Method Call with Parameters</b></p>
<div class="example-contents"><pre class="programlisting">&lt;?php
require_once 'Zend/XmlRpc/Client.php';

$client = new Zend_XmlRpc_Client('http://framework.zend.com/xmlrpc');

$arg1 = 1.1;
$arg2 = 'foo';

$result = $client-&gt;call('test.sayHello', array($arg1, $arg2));

// $result is a native PHP type
            </pre></div>
</div>
<br class="example-break"><p>
            If the remote method doesn't require parameters, this optional
            parameter may either be left out or an empty <code class="code">array()</code>
            passed to it. The array of parameters for the remote method can
            contain native PHP types, <code class="code">Zend_XmlRpc_Value</code>
            objects, or a mix of each.
        </p>
<p>
            The <code class="code">call()</code> method will automatically convert the
            XML-RPC response and return its equivalent PHP native type. A
            <code class="code">Zend_XmlRpc_Response</code> object for the return value will
            also be available by calling the <code class="code">getLastResponse()</code>
            method after the call.
        </p>
</div>
<div class="sect2" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="zend.xmlrpc.value.parameters"></a>49.2.3. Types and Conversions</h3></div></div></div>
<p>
            Some remote method calls require parameters.  These are given to
            the <code class="code">call()</code> method of <code class="code">Zend_XmlRpc_Client</code>
            as an array in the second parameter.  Each parameter may be
            given as either a native PHP type which will be automatically
            converted, or as an object representing a specific XML-RPC type
            (one of the <code class="code">Zend_XmlRpc_Value</code> objects).
        </p>
<div class="sect3" lang="en">
<div class="titlepage"><div><div><h4 class="title">
<a name="zend.xmlrpc.value.parameters.php-native"></a>49.2.3.1. PHP Native Types as Parameters</h4></div></div></div>
<p>
                Parameters may be passed to <code class="code">call()</code> as native PHP
                variables, meaning as a <code class="code">string</code>,
                <code class="code">integer</code>, <code class="code">float</code>,
                <code class="code">boolean</code>, <code class="code">array</code>, or an
                <code class="code">object</code>. In this case, each PHP native type will
                be auto-detected and converted into one of the XML-RPC types
                according to this table:
            </p>
<div class="table">
<a name="zend.xmlrpc.value.parameters.php-native.table-1"></a><p class="title"><b>Table 49.1. PHP and XML-RPC Type Conversions</b></p>
<div class="table-contents"><table summary="PHP and XML-RPC Type Conversions" border="1">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>PHP Native Type</th>
<th>XML-RPC Type</th>
</tr></thead>
<tbody>
<tr>
<td>integer</td>
<td>int</td>
</tr>
<tr>
<td>double</td>
<td>double</td>
</tr>
<tr>
<td>boolean</td>
<td>boolean</td>
</tr>
<tr>
<td>string</td>
<td>string</td>
</tr>
<tr>
<td>array</td>
<td>array</td>
</tr>
<tr>
<td>associative array</td>
<td>struct</td>
</tr>
<tr>
<td>object</td>
<td>array</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><div class="note"><table border="0" summary="Note: What type do empty arrays get cast to?">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td>
<th align="left">What type do empty arrays get cast to?</th>
</tr>
<tr><td align="left" valign="top">
<p>
                    Passing an empty array to an XML-RPC method is problematic,
                    as it could represent either an array or a struct.
                    <code class="code">Zend_XmlRpc_Client</code> detects such conditions and
                    makes a request to the server's
                    <code class="code">system.methodSignature</code> method to determine the
                    appropriate XML-RPC type to cast to.
                </p>
<p>
                    However, this in itself can lead to issues. First off,
                    servers that do not support
                    <code class="code">system.methodSignature</code> will log failed
                    requests, and <code class="code">Zend_XmlRpc_Client</code> will resort to
                    casting the value to an XML-RPC array type. Additionally,
                    this means that any call with array arguments will result in
                    an additional call to the remote server.
                </p>
<p>
                    To disable the lookup entirely, you can call the
                    <code class="code">setSkipSystemLookup()</code> method prior to making
                    your XML-RPC call:
                </p>
<pre class="programlisting">
$client-&gt;setSkipSystemLookup(true);
$result = $client-&gt;call('foo.bar', array(array()));
</pre>
</td></tr>
</table></div>
</div>
<div class="sect3" lang="en">
<div class="titlepage"><div><div><h4 class="title">
<a name="zend.xmlrpc.value.parameters.xmlrpc-value"></a>49.2.3.2. <code class="code">Zend_XmlRpc_Value</code> Objects as Parameters</h4></div></div></div>
<p>
                Parameters may also be created as <code class="code">Zend_XmlRpc_Value</code>
                instances to specify an exact XML-RPC type.  The primary reasons
                for doing this are:

                </p>
<div class="itemizedlist"><ul type="disc">
<li><p>
                            When you want to make sure the correct parameter
                            type is passed to the procedure (i.e. the
                            procedure requires an integer and you may get it
                            from a database as a string)
                        </p></li>
<li><p>
                            When the procedure requires <code class="code">base64</code> or
                            <code class="code">dateTime.iso8601</code> type (which doesn't exists as a
                            PHP native type)
                        </p></li>
<li><p>
                            When auto-conversion may fail (i.e. you want to
                            pass an empty XML-RPC struct as a parameter. Empty
                            structs are represented as empty arrays in PHP
                            but, if you give an empty array as a parameter it
                            will be auto-converted to an XML-RPC array since
                            it's not an associative array)
                        </p></li>
</ul></div>
<p>
            </p>
<p>
                There are two ways to create a <code class="code">Zend_XmlRpc_Value</code>
                object: instantiate one of the <code class="code">Zend_XmlRpc_Value</code>
                subclasses directly, or use the static factory method
                <code class="code">Zend_XmlRpc_Value::getXmlRpcValue()</code>.
            </p>
<div class="table">
<a name="zend.xmlrpc.value.parameters.xmlrpc-value.table-1"></a><p class="title"><b>Table 49.2. <code class="code">Zend_XmlRpc_Value</code> Objects for XML-RPC Types</b></p>
<div class="table-contents"><table summary="Zend_XmlRpc_Value Objects for XML-RPC Types" border="1">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>XML-RPC Type</th>
<th>
<code class="code">Zend_XmlRpc_Value</code> Constant</th>
<th>
<code class="code">Zend_XmlRpc_Value</code> Object</th>
</tr></thead>
<tbody>
<tr>
<td>int</td>
<td><code class="code">Zend_XmlRpc_Value::XMLRPC_TYPE_INTEGER</code></td>
<td><code class="code">Zend_XmlRpc_Value_Integer</code></td>
</tr>
<tr>
<td>double</td>
<td><code class="code">Zend_XmlRpc_Value::XMLRPC_TYPE_DOUBLE</code></td>
<td><code class="code">Zend_XmlRpc_Value_Double</code></td>
</tr>
<tr>
<td>boolean</td>
<td><code class="code">Zend_XmlRpc_Value::XMLRPC_TYPE_BOOLEAN</code></td>
<td><code class="code">Zend_XmlRpc_Value_Boolean</code></td>
</tr>
<tr>
<td>string</td>
<td><code class="code">Zend_XmlRpc_Value::XMLRPC_TYPE_STRING</code></td>
<td><code class="code">Zend_XmlRpc_Value_String</code></td>
</tr>
<tr>
<td>base64</td>
<td><code class="code">Zend_XmlRpc_Value::XMLRPC_TYPE_BASE64</code></td>
<td><code class="code">Zend_XmlRpc_Value_Base64</code></td>
</tr>
<tr>
<td>dateTime.iso8601</td>
<td><code class="code">Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME</code></td>
<td><code class="code">Zend_XmlRpc_Value_DateTime</code></td>
</tr>
<tr>
<td>array</td>
<td><code class="code">Zend_XmlRpc_Value::XMLRPC_TYPE_ARRAY</code></td>
<td><code class="code">Zend_XmlRpc_Value_Array</code></td>
</tr>
<tr>
<td>struct</td>
<td><code class="code">Zend_XmlRpc_Value::XMLRPC_TYPE_STRUCT</code></td>
<td><code class="code">Zend_XmlRpc_Value_Struct</code></td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p>
                </p>
<div class="note"><table border="0" summary="Note: Automatic Conversion">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td>
<th align="left">Automatic Conversion</th>
</tr>
<tr><td align="left" valign="top"><p>
                        When building a new <code class="code">Zend_XmlRpc_Value</code>
                        object, its value is set by a PHP type. The PHP type
                        will be converted to the specified type using
                        PHP casting. For example, if a string is given as a
                        value to the <code class="code">Zend_XmlRpc_Value_Integer</code>
                        object, it will be converted using
                        <code class="code">(int)$value</code>.
                    </p></td></tr>
</table></div>
<p>
            </p>
</div>
</div>
<div class="sect2" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="zend.xmlrpc.client.requests-and-responses"></a>49.2.4. Server Proxy Object</h3></div></div></div>
<p>
            Another way to call remote methods with the XML-RPC client is to
            use the server proxy.  This is a PHP object that proxies a remote
            XML-RPC namespace, making it work as close to a native PHP object
            as possible.
        </p>
<p>
            To instantiate a server proxy, call the <code class="code">getProxy()</code>
            instance method of <code class="code">Zend_XmlRpc_Client</code>. This will
            return an instance of <code class="code">Zend_XmlRpc_Client_ServerProxy</code>.
            Any method call on the server proxy object will be forwarded to
            the remote, and parameters may be passed like any other PHP
            method.
        </p>
<div class="example">
<a name="zend.xmlrpc.client.requests-and-responses.example-1"></a><p class="title"><b>Example 49.3. Proxy the Default Namespace</b></p>
<div class="example-contents"><pre class="programlisting">&lt;?php
require_once 'Zend/XmlRpc/Client.php';

$client = new Zend_XmlRpc_Client('http://framework.zend.com/xmlrpc');

$server = $client-&gt;getProxy();           // Proxy the default namespace

$hello = $server-&gt;test-&gt;sayHello(1, 2);  // test.Hello(1, 2) returns "hello"
            </pre></div>
</div>
<br class="example-break"><p>
            The <code class="code">getProxy()</code> method receives an optional argument
            specifying which namespace of the remote server to proxy. If it
            does not receive a namespace, the default namespace will be
            proxied.  In the next example, the <code class="code">test</code> namespace
            will be proxied:
        </p>
<div class="example">
<a name="zend.xmlrpc.client.requests-and-responses.example-2"></a><p class="title"><b>Example 49.4. Proxy Any Namespace</b></p>
<div class="example-contents"><pre class="programlisting">&lt;?php
require_once 'Zend/XmlRpc/Client.php';

$client = new Zend_XmlRpc_Client('http://framework.zend.com/xmlrpc');

$test  = $client-&gt;getProxy('test');     // Proxy the "test" namespace

$hello = $test-&gt;sayHello(1, 2);         // test.Hello(1,2) returns "hello"
            </pre></div>
</div>
<br class="example-break"><p>
            If the remote server supports nested namespaces of any depth,
            these can also be used through the server proxy. For example, if
            the server in the example above had a method
            <code class="code">test.foo.bar()</code>, it could be called as
            <code class="code">$test-&gt;foo-&gt;bar()</code>.
        </p>
</div>
<div class="sect2" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="zend.xmlrpc.client.error-handling"></a>49.2.5. Error Handling</h3></div></div></div>
<p>
            Two kinds of errors can occur during an XML-RPC method call: HTTP
            errors and XML-RPC faults. The <code class="code">Zend_XmlRpc_Client</code>
            recognizes each and provides the ability to detect and trap them
            independently.
        </p>
<div class="sect3" lang="en">
<div class="titlepage"><div><div><h4 class="title">
<a name="zend.xmlrpc.client.error-handling.http"></a>49.2.5.1. HTTP Errors</h4></div></div></div>
<p>
                If any HTTP error occurs, such as the remote HTTP server
                returns a <code class="code">404 Not Found</code>, a
                <code class="code">Zend_XmlRpc_Client_HttpException</code> will be thrown.
            </p>
<div class="example">
<a name="zend.xmlrpc.client.error-handling.http.example-1"></a><p class="title"><b>Example 49.5. Handling HTTP Errors</b></p>
<div class="example-contents"><pre class="programlisting">&lt;?php
require_once 'Zend/XmlRpc/Client.php';

$client = new Zend_XmlRpc_Client('http://foo/404');

try {

    $client-&gt;call('bar', array($arg1, $arg2));

} catch (Zend_XmlRpc_Client_HttpException $e) {

    // $e-&gt;getCode() returns 404
    // $e-&gt;getMessage() returns "Not Found"

}
                </pre></div>
</div>
<br class="example-break"><p>
                Regardless of how the XML-RPC client is used, the
                <code class="code">Zend_XmlRpc_Client_HttpException</code> will be thrown
                whenever an HTTP error occurs.
            </p>
</div>
<div class="sect3" lang="en">
<div class="titlepage"><div><div><h4 class="title">
<a name="zend.xmlrpc.client.error-handling.faults"></a>49.2.5.2. XML-RPC Faults</h4></div></div></div>
<p>
                An XML-RPC fault is analogous to a PHP exception. It is a
                special type returned from an XML-RPC method call that has
                both an error code and an error message. XML-RPC faults are
                handled differently depending on the context of how the
                <code class="code">Zend_XmlRpc_Client</code> is used.
            </p>
<p>
                When the <code class="code">call()</code> method or the server
                proxy object is used, an XML-RPC fault will result in a
                <code class="code">Zend_XmlRpc_Client_FaultException</code> being thrown.
                The code and message of the exception will map directly to
                their respective values in the original XML-RPC fault
                response.
            </p>
<div class="example">
<a name="zend.xmlrpc.client.error-handling.faults.example-1"></a><p class="title"><b>Example 49.6. Handling XML-RPC Faults</b></p>
<div class="example-contents"><pre class="programlisting">&lt;?php
require_once 'Zend/XmlRpc/Client.php';

$client = new Zend_XmlRpc_Client('http://framework.zend.com/xmlrpc');

try {

    $client-&gt;call('badMethod');

} catch (Zend_XmlRpc_Client_FaultException $e) {

    // $e-&gt;getCode() returns 1
    // $e-&gt;getMessage() returns "Unknown method"

}
                </pre></div>
</div>
<br class="example-break"><p>
                When the <code class="code">call()</code> method is used to make the
                request, the <code class="code">Zend_XmlRpc_Client_FaultException</code> will be
                thrown on fault. A <code class="code">Zend_XmlRpc_Response</code> object
                containing the fault will also be available by calling
                <code class="code">getLastResponse()</code>.
            </p>
<p>
                When the <code class="code">doRequest()</code> method is used to make the
                request, it will not throw the exception. Instead, it will
                return a <code class="code">Zend_XmlRpc_Response</code> object returned
                will containing the fault. This can be checked with
                <code class="code">isFault()</code> instance method of
                <code class="code">Zend_XmlRpc_Response</code>.
            </p>
</div>
</div>
<div class="sect2" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="zend.xmlrpc.client.introspection"></a>49.2.6. Server Introspection</h3></div></div></div>
<p>
            Some XML-RPC servers support the de facto introspection methods under the XML-RPC
            <code class="code">system.</code> namespace.  <code class="code">Zend_XmlRpc_Client</code> provides special
            support for servers with these capabilities.
        </p>
<p>
            A <code class="code">Zend_XmlRpc_Client_ServerIntrospection</code> instance may be retrieved by calling
            the <code class="code">getIntrospector()</code> method of <code class="code">Zend_XmlRpcClient</code>.  It can
            then be used to perform introspection operations on the server.
        </p>
</div>
<div class="sect2" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="zend.xmlrpc.client.request-to-response"></a>49.2.7. From Request to Response</h3></div></div></div>
<p>
            Under the hood, the <code class="code">call()</code> instance method of <code class="code">Zend_XmlRpc_Client</code>
            builds a request object (<code class="code">Zend_XmlRpc_Request</code>) and sends it to another method,
            <code class="code">doRequest()</code>, that returns a response object (<code class="code">Zend_XmlRpc_Response</code>).
        </p>
<p>
            The <code class="code">doRequest()</code> method is also available for use directly:
        </p>
<div class="example">
<a name="zend.xmlrpc.client.request-to-response.example-1"></a><p class="title"><b>Example 49.7. Processing Request to Response</b></p>
<div class="example-contents"><pre class="programlisting">&lt;?php
require_once 'Zend/XmlRpc/Client.php';

$client = new Zend_XmlRpc_Client('http://framework.zend.com/xmlrpc');

$request = new Zend_XmlRpc_Request();
$request-&gt;setMethod('test.sayHello');
$request-&gt;setParams(array('foo', 'bar'));

$client-&gt;doRequest($request);

// $server-&gt;getLastRequest() returns instanceof Zend_XmlRpc_Request
// $server-&gt;getLastResponse() returns instanceof Zend_XmlRpc_Response
            </pre></div>
</div>
<br class="example-break"><p>
            Whenever an XML-RPC method call is made by the client through any
            means, either the <code class="code">call()</code> method,
            <code class="code">doRequest()</code> method, or server proxy, the last request
            object and its resultant response object will always be available
            through the methods <code class="code">getLastRequest()</code> and
            <code class="code">getLastResponse()</code> respectively.
        </p>
</div>
<div class="sect2" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="zend.xmlrpc.client.http-client"></a>49.2.8. HTTP Client and Testing</h3></div></div></div>
<p>
            In all of the prior examples, an HTTP client was never specified.
            When this is the case, a new instance of
            <code class="code">Zend_Http_Client</code> will be created with its default
            options and used by <code class="code">Zend_XmlRpc_Client</code> automatically.
        </p>
<p>
            The HTTP client can be retrieved at any time with the
            <code class="code">getHttpClient()</code> method. For most cases, the default
            HTTP client will be sufficient. However, the
            <code class="code">setHttpClient()</code> method allows for a different HTTP
            client instance to be injected.
        </p>
<p>
            The <code class="code">setHttpClient()</code> is particularly useful for unit testing.  When combined
            with the <code class="code">Zend_Http_Client_Adapter_Test</code>, remote services can be mocked
            out for testing.  See the unit tests for <code class="code">Zend_XmlRpc_Client</code> for examples
            of how to do this.
        </p>
</div>
</div>
<div class="navfooter"><table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="zend.xmlrpc.html">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="zend.xmlrpc.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="zend.xmlrpc.server.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Chapter 49. Zend_XmlRpc </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> 49.3. Zend_XmlRpc_Server</td>
</tr>
</table></div>
<div class="revinfo"></div>
</body>
</html>
